<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class SendEmail extends Mailable
{
    use Queueable, SerializesModels;

    // 邮件视图
    public $view ;

    // 邮件subject
    public $subject = '通知';

    /**
     * Create a new message instance.
     *
     * SendEmail constructor.
     * @param $subject
     * @param string $view
     * * @param array $viewData
     */
    public function __construct($subject,$view,$viewData = [])
    {
        if (!empty($subject)){
            $this->subject($subject);
        }
        if (!empty($view)){
            $this->view = $view;
        }
        if ( !view()->exists($this->view)){
            abort(404);
        }
        if (!empty($viewData)){
            $this->with('viewData',$viewData);
        }
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view($this->view);
    }
}
